package com.example.navmenu.controller;

import com.example.item.Foot;
import com.example.navmenu.service.FootService;
import com.example.smartcommon.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/foot/")
@Tag(name = "显示页脚数据")
public class FootController {
    @Autowired
    private FootService footService;

    @Operation(summary = "获得所有的页脚数据")
    @GetMapping(value = "/getAllFoot")
    public R getAllFoot() {
        List<Foot> footList = footService.list();
        return R.ok("查询所有页脚数据成功").data("footList", footList);
    }
    
    @Operation(summary = "增加页脚")
    @PostMapping(value = "/addFoot")
    public R addFoot(@RequestBody Foot foot) {
        boolean flag = footService.save(foot);
        if (flag) {
            return R.ok("增加页脚成功");
        } else {
            return R.error("增加页脚失败");
        }
    }

    @Operation(summary = "删除页脚数据")
    @GetMapping(value = "/deleteFoot/{id}")
    public R deleteFoot(@PathVariable("id") Integer footId) {
        boolean flag = footService.removeById(footId);
        if (flag) {
            return R.ok("删除页脚成功");
        } else {
            return R.error("删除页脚失败");
        }
    }

    @Operation(summary = "按照页脚编号查询数据")
    @GetMapping(value = "/getFootById/{id}")
    public R getByIdFoot(@PathVariable("id") Integer footId) {
        Foot foot = footService.getById(footId);
        return R.ok("按照页脚编号查询数据成功").data("foot", foot);
    }

    @Operation(summary = "修改页脚数据")
    @PostMapping(value = "/updateFoot")
    public R updateFoot(@RequestBody Foot foot) {
        boolean flag = footService.updateById(foot);
        if (flag) {
            return R.ok("删除页脚成功");
        } else {
            return R.error("删除页脚失败");
        }
    }
}
